﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace X3DXNA.customTypes
{
    /// <summary>
    /// The SFTime field specifies a single time value. Time values are specified as a double-precision floating point number.
    /// Time values are specified as the number of seconds from a specific time origin. 
    /// SFTime fields represent the number of seconds since Jan 1, 1970, 00:00:00 GMT.
    /// </summary>
    public struct SFTime
    {
        double value;

        /// <summary>
        /// Builds an SFTime that represent the time expressed in argument.
        /// </summary>
        /// <param name="value"></param>
        public SFTime(double value)
        {
            this.value = value;
        }

        #region Static Methods

        /// <summary>
        /// Gets an SFTime object that is set to the current time on this computer.
        /// </summary>
        public static SFTime Now {
            get
            {
                return new SFTime((DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds);
            }
        }

        #endregion

        #region Override Methods & Binary Operators (Equals, +, -, *, /, <, >, ==)

        /// <summary>
        /// Converts the numeric value of this instance to its equivalent string representation.
        /// </summary>
        /// <returns>The string representation of the value of this instance.</returns>
        public override string ToString()
        {
            return this.value.ToString();
        }

        public static SFTime operator +(SFTime time1, SFTime time2)
        {
            return new SFTime(time1.value + time2.value);
        }

        public static SFTime operator -(SFTime time1, SFTime time2)
        {
            return new SFTime(time1.value - time2.value);
        }

        public static SFTime operator *(SFTime time1, SFTime time2)
        {
            return new SFTime(time1.value * time2.value);
        }

        public static SFTime operator /(SFTime time1, SFTime time2)
        {
            return new SFTime(time1.value / time2.value);
        }

        public static bool operator <(SFTime time1, SFTime time2)
        {
            return (time1.value < time2.value);
        }

        public static bool operator >(SFTime time1, SFTime time2)
        {
            return (time1.value > time2.value);
        }

        public static bool operator ==(SFTime time1, SFTime time2)
        {
            return (time1.value == time2.value);
        }

        public static bool operator !=(SFTime time1, SFTime time2)
        {
            return (time1.value != time2.value);
        }

        public static implicit operator float(SFTime time)
        {
            return (float)time.value;
        }

        #endregion
    }
}
